var sharedData=require("dataMgr");
//处理角色道具相关得脚本
cc.Class({
    extends: cc.Component,

    properties: {
        //是否获得加速道具
        isInPropSpeed:false,
        //是否获得提高攻击力的道具
        isInPropPower:false,
        //是否获得多条弹道道具
        isInPropMult:false,
        propBg:cc.Node,
        propLabelPrefab:cc.Prefab
    },

    resetRole:function(){
        this.node.scale=1;
        this.node.x=0;
        this.node.tag=0;
        this.node.active=true;
        this.propBg.active=false;
        this.resetAction();
    },


    resetAction:function(){
        this.isInPropMult=false;
        this.isInPropPower=false;
        this.isInPropSpeed=false;
        this.propBg.stopAllActions();
    },

    setInPropSpeed:function(color){
        let time=sharedData.speedProp.keepTime;
        if(time<3){
            time=3;
        }
        this.resetAction();
        //设置道具
        this.isInPropSpeed=true;
        this.propBg.active=true;
        //设置可显示
        this.propBg.color=color;
        this.propBg.opacity=255;
        this.propBg.runAction(cc.sequence(cc.delayTime(time-3),cc.blink(3,3),cc.callFunc(function(){
            //运行完成后回调
            this.isInPropSpeed=false;
            this.propBg.active=false;
        }.bind(this),this)));
        this.addLabelInfo(0);
    },

    setInPropPower:function(color){
        let time=sharedData.powerProp.keepTime;
        if(time<3){
            time=3;
        }
        this.resetAction();
        //设置道具
        this.isInPropPower=true;
        //设置可显示
        this.propBg.color=color;
        this.propBg.active=true;
        this.propBg.opacity=255;
        this.propBg.runAction(cc.sequence(cc.delayTime(time-3),cc.blink(3,3),cc.callFunc(function(){
            //运行完成后回调
            this.isInPropPower=false;
            this.propBg.active=false;
        }.bind(this),this)));
        this.addLabelInfo(1);
    },

    setInPropMult:function(color){
        let time=sharedData.multButProp.keepTime;
        if(time<3){
            time=3;
        }
        this.resetAction();
        this.isInPropMult=true;
        this.propBg.active=true;
        this.propBg.opacity=255;
        //设置可显示
        this.propBg.color=color;
        this.propBg.runAction(cc.sequence(cc.delayTime(time-3),cc.blink(3,3),cc.callFunc(function(){
            //运行完成后回调
            this.isInPropMult=false;
            this.propBg.active=false;
        }.bind(this),this)));
        this.addLabelInfo(2);
    },

    addLabelInfo:function(type){
         let proplabel=cc.instantiate(this.propLabelPrefab);
         proplabel.getComponent("proplabel").initData(type);
         proplabel.position=cc.p(0,-this.node.height/2-proplabel.height/2-20);
         this.node.addChild(proplabel);
    }
});
